import 'package:flutter/material.dart';
import 'package:osc/common/osc_user_manager.dart';
import 'package:osc/ui/pages/tweet/tweet_list.dart';
import 'package:osc/ui/widgets/common_tab_bar.dart';


///动弹
class Tweet extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return new TweetState();
  }
}

class TweetState extends State<Tweet> with TickerProviderStateMixin<Tweet>, AutomaticKeepAliveClientMixin<Tweet> {
  double width = 0;
  double height = 0;

  TabController tabController;
  int currentTabIndex = 0;
  int tempTabIndex = 0;


  @override
  void initState() {
    super.initState();
    tabController = TabController(length: 3, vsync: this);
    tabController.addListener(() {
      currentTabIndex = tabController.index;
      if (tempTabIndex == currentTabIndex) {
        return;
      }
      tempTabIndex = currentTabIndex;
    });
  }

  @override
  void dispose() {
    tabController?.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    super.build(context);
    if(width == 0) {
      Size size = MediaQuery.of(context).size;
      width = size.width;
      height = size.height;
    }
    return CommonTabBar(
        tabs: [
          Tab(text:"最新"),
          Tab(text:"热门"),
          Tab(text:"我的"),
        ],
        pages: [
          TweetList(type: 1),
          TweetList(type: 2, enableLoadMore: false),
          TweetList(userId: OscUserManager().userId, needLogin: true,),
        ],
    );
  }

  @override
  bool get wantKeepAlive => true;
}
